//c
#if 0

//init()
//push()
//pop()
//print()

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

typedef struct tagSNode {
	int value;
	struct tagSNode* next;
}SNode;

typedef struct {
	SNode* front;
	SNode** prear;
}LinkQueue;

void Init(LinkQueue* q) {
	q->front = (SNode*)malloc(sizeof(SNode));
	q->front->next = NULL;
	q->prear = &q->front->next;
}

void push(LinkQueue* pHead, int value) {
	SNode** prear = pHead->prear;
	assert(pHead->front != NULL);
	
	SNode* newNode = (SNode*)malloc(sizeof(SNode));
	newNode->value = value;
	newNode->next = *prear;
	*prear = newNode;
	pHead->prear = &newNode->next;
}

int pop(LinkQueue* pHead) {
	assert(pHead->front != NULL && pHead->front->next != NULL);

	SNode* delNode = pHead->front->next;
	int t = delNode->value;
	pHead->front->next = delNode->next;
	return t;
}

void print(LinkQueue* pHead) {
	assert(pHead->front != NULL);

	char* seperator = "";
	printf("The LinkQueu From front to rear: ");
	SNode* curr = pHead->front->next;
	while(curr != NULL) {
		printf("%s%d", seperator, curr->value);
		curr = curr->next;
		seperator = "->";
	}

	printf("\n");
}

int main() {
	LinkQueue q;
	Init(&q);
	print(&q);

	for (int i = 0; i < 3; ++i) {
		push(&q, i);
	}
	print(&q);

	int re = pop(&q);
	printf("%d", re);
	print(&q);

	re = pop(&q);
	printf("%d", re);

	re = pop(&q);
	printf("%d", re);
	print(&q);

	system("pause");
}

#endif